<template>
    <s-table style="overflow: auto;">
        <s-thead>
            <s-tr style="position: sticky;top: 0;">
                <s-th>时间</s-th>
                <s-th>星期一</s-th>
                <s-th>星期二</s-th>
                <s-th>星期三</s-th>
                <s-th>星期四</s-th>
                <s-th>星期五</s-th>
                <s-th>星期六</s-th>
                <s-th>星期日</s-th>
            </s-tr>
        </s-thead>
        <s-tbody>
            <s-tr v-for="(item, i) in table[0]" :key="i">
                <s-td v-for="(item1, i2) in table.length + 1" :key="it">
                    <span v-if="i2 == 0">
                        {{ table[0][i].time.length == 2 ? table[0][i].time[0] + " - " + table[0][i].time[1] :
                            table[0][i].time[0] }}
                    </span>
                    <span v-if="table[i2 - 1] == null">

                    </span>
                    <span v-else-if="table[i2 - 1][i].type == 'bigBreak'">
                        大课间
                    </span>
                    <span v-else-if="table[i2 - 1][i].type == 'finishClass'" style="text-shadow: #9f87fb 3px 3px 3px;">
                        下课
                    </span>
                    <span v-else-if="table[i2 - 1][i].type == 'lunch'" style="color: skyblue;">
                        午餐
                    </span>
                    <span v-else-if="table[i2 - 1][i].type == 'noonBreak'" style="color: skyblue;">
                        午休
                    </span>
                    <span v-else-if="table[i2 - 1][i].type == 'over'" style="color:green">
                        放学
                    </span>
                    <span v-else-if='table[i2 - 1][i].type == "lesson" || "morningReading" || "afternoonClass"'
                        style="color:red;font-size: 17px;">
                        {{ table[i2 - 1][i].type == "morningReading" ? "早读 : " + table[i2 - 1][i].name : table[i2 -
                            1][i].name }}
                        <p style="color: black;font-size: 14px;"><span v-for="ite in table[i2 - 1][i].teacher">{{ ite +
                                " "}} </span></p>
                    </span>

                </s-td>
            </s-tr>

        </s-tbody>
    </s-table>
</template>

<script setup>
import { ref } from "vue"
let le = [{
    type: "morningReading",
    name: "数学",
    teacher: ["张三", "李四"],
    time: [
        "6:45",
        "7:30"
    ],
},
{
    type: "finishClass",
    time: [
        "7:30",
        "7:45",
    ]
},
{
    type: "lesson",
    name: "数学",
    teacher: ["张三", "李四"],
    time: [
        "7:45",
        "8:30",
    ],
}
    ,
{
    type: "finishClass",
    time: [
        "8:30",
        "8:45",
    ]
},
{
    type: "lesson",
    name: "数学",
    teacher: ["张三", "李四"],
    time: [
        "8:45",
        "9:30",
    ],
}
    ,
{
    type: "bigBreak", // 大课间
    time: [
        "9:30",
        "10:00",
    ]
},
{
    type: "lesson",
    name: "数学",
    teacher: ["张三", "李四"],
    time: [
        "10:00",
        "10:45",
    ],
},
{
    type: "finishClass",
    time: [
        "10:45",
        "11:00"
    ]
},
{
    type: "lesson",
    name: "数学",
    teacher: ["张三", "李四"],
    time: [
        "11:00",
        "11:45",
    ],
},
{
    type: "lunch",
    time: [
        "11:45",
        "12:15",
    ]
},
{
    type: "lesson",
    name: "数学",
    teacher: ["张三", "李四"],
    time: [
        "12:15",
        "12:45",
    ],
},
{
    type: "noonBreak",
    time: [
        "12:45",
        "13:15",
    ]
},
{
    type: "lesson",
    name: "数学",
    teacher: ["张三", "李四"],
    time: [
        "13:15",
        "14:00",
    ],
},
{
    type: "finishClass",
    time: [
        "14:00",
        "14:15",
    ]
},
{
    type: "lesson",
    name: "数学",
    teacher: ["张三", "李四"],
    time: [
        "14:15",
        "15:00",
    ],
},
{
    type: "finishClass",
    time: [
        "15:00",
        "16:45",
    ]
},
{
    type: "lesson",
    name: "数学",
    teacher: ["张三", "李四"],
    time: [
        "16:45",
        "17:30",
    ],
},
{
    type: "finishClass",
    time: [
        "17:30",
        "18:45",
    ]
},
{
    type: "afternoonClass",
    name: "数学",
    teacher: ["张三", "李四"],
    time: [
        "18:45",
        "19:30",
    ],
},
{
    type: "over",
    time: [
        "15:30",
    ]
}]

let l = [{
    type: "morningReading",
    name: "数学",
    teacher: ["张三", "李四"],
    time: [
        "6:45",
        "7:30"
    ],
},
{
    type: "finishClass",
    time: [
        "7:30",
        "7:45",
    ]
},
{
    type: "lesson",
    name: "数学",
    teacher: ["张三", "李四"],
    time: [
        "7:45",
        "8:30",
    ],
}
    ,
{
    type: "finishClass",
    time: [
        "8:30",
        "8:45",
    ]
},
{
    type: "lesson",
    name: "数学",
    teacher: ["张三", "李四"],
    time: [
        "8:45",
        "9:30",
    ],
}
    ,
{
    type: "bigBreak", // 大课间
    time: [
        "9:30",
        "10:00",
    ]
},
{
    type: "lesson",
    name: "数学",
    teacher: ["张三", "李四"],
    time: [
        "10:00",
        "10:45",
    ],
},
{
    type: "finishClass",
    time: [
        "10:45",
        "11:00"
    ]
},
{
    type: "lesson",
    name: "数学",
    teacher: ["张三", "李四"],
    time: [
        "11:00",
        "11:45",
    ],
},
{
    type: "lunch",
    time: [
        "11:45",
        "12:15",
    ]
},
{
    type: "lesson",
    name: "数学",
    teacher: ["张三", "李四"],
    time: [
        "12:15",
        "12:45",
    ],
},
{
    type: "noonBreak",
    time: [
        "12:45",
        "13:15",
    ]
},
{
    type: "lesson",
    name: "数学",
    teacher: ["张三", "李四"],
    time: [
        "13:15",
        "14:00",
    ],
},
{
    type: "finishClass",
    time: [
        "14:00",
        "14:15",
    ]
},
{
    type: "lesson",
    name: "数学",
    teacher: ["张三", "李四"],
    time: [
        "14:15",
        "15:00",
    ],
},
{
    type: "lesson",
    name: "信息技术",
    teacher: ["张三", "李四"],
    time: [
        "15:00",
        "16:50",
    ],
},
]
let table = ref([
    l, l, l, l, l, l, l
])



console.log(table);

function panduanTime() {
    // 获取当前unix时间戳
    let nowTime = new Date().getTime() / 1000;
    console.log(nowTime);
    // 获取当前星期几
    let week = new Date().getDay();
    console.log(week);
    // 处于当前时间的课程
    for (let i = 0; i < table.value[week - 1].length; i++) {
        let ele = table.value[week - 1][i];
        for (let j = 0; j < ele.time.length; j++) {
            let tableTime = getUnixTime(ele.time[j]);
            if (tableTime >= nowTime) {
                print(ele.type, ele.time,ele.name)
                // 计算距离下课的时间
                if (ele.time.length > 1) {
                    let time = tableTime - nowTime;
                    print("距离下课还有", time/60, "分钟")
                    // 根据ysMap 和 dzMap 将课程名称转换为简写
                    for (let k = 0; k < ysMap.length; k++) {
                        if (ele.name === ysMap[k]) {
                            print(dzMap[k])
                        }
                    }



                }
                return
            }
        }
    }






    // 写一个辅助函数，将hh:mm 转换为当天的unix时间戳
    function getUnixTime(timeStr) {
        let [h, m] = timeStr.split(':').map(Number);
        let now = new Date().toISOString().split('T')[0];
        return new Date(`${now} ${h}:${m}`).getTime() / 1000;
    }



}


let ysMap = [
    "语文",
    "数学",
    "英语",
    "物理",
    "化学",
    "生物",
    "政治",
    "历史",
    "地理",
    "体育",
    "美术",
    "音乐",
    "信息技术",
    "综合",
    "通用",
    "社团",
    "班会"
]
let dzMap = [
    "语",
    "数",
    "英",
    "物",
    "化",
    "生",
    "政",
    "史",
    "地",
    "体",
    "术",
    "音",
    "技",
    "综",
    "通",
    "社",
    "班"
]
//setInterval(panduanTime, 1000)


</script>

<style scoped></style>